<template>
  <div class="pagination-wrapper">
    <div>
      <span style="padding:5px 20px 5px 0"
      >共 {{ total }} 条结果 第 {{ current }} /
        {{ Math.ceil(total / pageSize) }} 页</span
      >
    </div>
    <a-pagination
      :pageSizeOptions="pageSizeOptions"
      :total="total"
      :showSizeChanger="showSizeChanger"
      showQuickJumper
      v-model="current_page"
      :pageSize="pageSize"
      @showSizeChange="onShowSizeChange"
      @change="pageChange"
      style="margin-right: -8px;"
    >
    </a-pagination>
  </div>
</template>

<script>
import {pageConfig} from '@/config'

export default {
  props: {
    total: {
      type: Number,
      default: 0
    },
    current: {
      type: Number || String,
      default: 1
    },
    defaultPageSize: 0,
    showSizeChanger: {
      type:Boolean,
      default:true
    },
  },
  data () {
    return {
      pageSizeOptions: pageConfig.pageSizeOptions,
      pageSize: pageConfig.pageSize,
      current_page: 1
    }
  },
  mounted () {
    this.current_page = +this.current
    if (this.defaultPageSize) {
      this.pageSize = this.defaultPageSize
    }
  },
  methods: {
    onShowSizeChange (current, size) {
      this.pageSize = size
      this.$emit('pageChange', current, size)
    },
    pageChange (page, pageSize) {
      this.$emit('pageChange', page, pageSize)
    },
    refresh () {
      this.$emit('pageChange', this.current, this.pageSize)
    }
  },
  watch: {
    current (val) {
      this.current_page = +val
    }
  }
}
</script>

<style scoped lang="scss">
.pagination-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
</style>
